package com.xiaomage.view.draw9

import android.content.Context
import android.graphics.*
import android.view.View

/**
 * Created by Administrator on 2018/1/6.
 */
class MyDogView(context: Context): View(context) {
    private lateinit var bitmap: Bitmap
    private var bitmapHeight=0
    private val paint=getPaint()
    private val paint2=getPaint()
    private val paint3=getPaint()
    private val paint4=getPaint()
    private val paint5=getPaint()
    private val paint6=getPaint()
    private val paint7=getPaint()
    private val paint8=getPaint()
    private val paint9=getPaint()
    private val paint10=getPaint()
    private val paint11=getPaint()
    private val paint12=getPaint()
    private val paint13=getPaint()
    private val paint14=getPaint()
    private val paint15=getPaint()
    private val paint16=getPaint()
    private val paint17=getPaint()
    private val paint18=getPaint()
    private val paint19=getPaint()
    init {
        bitmap= BitmapFactory.decodeResource(resources, R.drawable.dog)
        bitmapHeight=500*bitmap.height/bitmap.width
    }
    override fun onDraw(canvas: Canvas) {
        super.onDraw(canvas)

        canvas.drawBitmap(bitmap,null,
                Rect(0, 0, 500, bitmapHeight),paint)

        canvas.translate(0f,bitmapHeight+50.toFloat())
        //Mode.MULTIPLY（正片叠底）
        paint2.colorFilter=PorterDuffColorFilter(
                Color.RED,
        PorterDuff.Mode.MULTIPLY
        )
        canvas.drawBitmap(bitmap,null,
                Rect(0, 0, 500, bitmapHeight),paint2)

        canvas.translate(0f,bitmapHeight+50.toFloat())
        //Mode.ADD(饱和度相加)
        paint3.colorFilter= PorterDuffColorFilter(
                Color.RED,
                PorterDuff.Mode.ADD
        )
        canvas.drawBitmap(bitmap,null,
                Rect(0, 0, 500, bitmapHeight),paint3)

        canvas.translate(0f,bitmapHeight+50.toFloat())
        //Mode.DARKEN（变暗）
        paint4.colorFilter= PorterDuffColorFilter(
                Color.RED,
                PorterDuff.Mode.DARKEN
        )
        canvas.drawBitmap(bitmap,null,
                Rect(0, 0, 500, bitmapHeight),paint4)

        canvas.translate(0f,bitmapHeight+50.toFloat())
        //Mode.LIGHTEN（变亮）
        paint5.colorFilter= PorterDuffColorFilter(
                Color.RED,
                PorterDuff.Mode.LIGHTEN
        )
        canvas.drawBitmap(bitmap,null,
                Rect(0, 0, 500, bitmapHeight),paint5)

        canvas.translate(0f,bitmapHeight+50.toFloat())
        //Mode.OVERLAY（叠加）
        paint6.colorFilter= PorterDuffColorFilter(
                Color.RED,
                PorterDuff.Mode.OVERLAY
        )
        canvas.drawBitmap(bitmap,null,
                Rect(0, 0, 500, bitmapHeight),paint6)

        canvas.translate(0f,bitmapHeight+50.toFloat())
        //Mode.SCREEN（滤色）
        paint7.colorFilter= PorterDuffColorFilter(
                Color.RED,
                PorterDuff.Mode.SCREEN
        )
        canvas.drawBitmap(bitmap,null,
                Rect(0, 0, 500, bitmapHeight),paint7)

        canvas.translate(0f,bitmapHeight+50.toFloat())
        //Mode.CLEAR和Mode.XOR他们在这里的效果是完成一致的，就是把图像清空，
        // 所以一旦应用他们两个中的任何一个，所得到的结果图像就是一个空图
        paint8.colorFilter= PorterDuffColorFilter(
                Color.RED,
                PorterDuff.Mode.CLEAR
        )
        canvas.drawBitmap(bitmap,null,
                Rect(0, 0, 500, bitmapHeight),paint8)

        canvas.translate(0f,bitmapHeight+50.toFloat())
        //Mode.CLEAR和Mode.XOR他们在这里的效果是完成一致的，就是把图像清空，
        // 所以一旦应用他们两个中的任何一个，所得到的结果图像就是一个空图
        paint9.colorFilter= PorterDuffColorFilter(
                Color.RED,
                PorterDuff.Mode.XOR
        )
        canvas.drawBitmap(bitmap,null,
                Rect(0, 0, 500, bitmapHeight),paint9)


    }

    private fun getPaint(): Paint {
        val paint= Paint()
        paint.isAntiAlias=true
        paint.strokeWidth=5f
        paint.style= Paint.Style.STROKE
        return paint
    }
}